﻿using Blm.Utils.Extensions;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using VisionCloud.Core.Model.Ms;
using VisionCloud.Domain.DtoModel.Ms;
using VisionCloud.Domain.Repository.Interface.Ms;

namespace VisionCloud.Domain.Repository.Implement.Ms
{
    public class MsDiagnosticReportRepository : BaseRepository<MsDiagnosticReport>, IMsDiagnosticReportRepository
    {
        /// <summary>
        /// 根据项目和楼栋查询诊断报告数据
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public async Task<MsDiagnosticReport> GetMsDiagnosticReport(MsDiagnosticReportRequestDto query)
        {
            return await Db.MsDiagnosticReports.Where(
                x => x.ProjectId == query.ProjectId.ToGuid() 
                && x.BuildingName == query.BuildingName 
                && x.ProjectStandardId == query.ProjectStandardId
                && x.CompanyId == query.CompanyId
                && (x.FloorName == query.FloorName)
                && (x.TaskType == query.TaskType)
                && (x.TaskProperty == query.TaskProperty)
                && !x.IsDeleted).FirstOrDefaultAsync().ConfigureAwait(false);
        }

        /// <summary>
        /// 根据项目和楼栋查询诊断报告数据
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public async Task<List<MsDiagnosticReport>> GetMsDiagnosticReportData(MsDiagnosticReportRequestDto query)
        {
            return await Db.MsDiagnosticReports.Where(
                x => x.FileName == query.FileName
                && !x.IsDeleted).ToListAsync().ConfigureAwait(false);
        }
    }
}